﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Threading;
using System.Globalization;
using Nivdal.AuxCode;

namespace Nivdal
{
    public partial class QnATips : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            OnlineUser ou = (OnlineUser)Session["User"];
            
            NewTipPanel.Visible = IsUserAnEditor();
            this.Title = Resources.Resource.Default_PageTitle + ", " + Resources.Resource.Tips_PageTitle;
            
            //Title = Resources.Resource.Tips_PageTitle + " - www.nivdal.com!";
            
            if (!IsPostBack)
            {
                TipsDataSource.SelectParameters.Add("Language", ou.Language);
            }
        }

        protected void ChangeLanguage(object sender, EventArgs e)
        {
            TipsDataSource.SelectParameters.Clear();
            TipsDataSource.SelectParameters.Add("Language", LanguageDropDownList.SelectedValue);
            TipsDataSource.DataBind();
            TipsListView.DataBind();
        }

        protected bool IsUserAnEditor()
        {
            OnlineUser ou = (OnlineUser)Session["User"]; 
            return ou.IsQnAEditor;
        }
        protected override void InitializeCulture()
        {
            OnlineUser ou = (OnlineUser)Session["User"];
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(ou.UICulture);
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(ou.Culture);
        }

        protected string DeleteConformation()
        { 
            return ("return confirm('" + Resources.Resource.Tips_SureDelete + "');");
        }

        protected void AddNewTip(object sender, EventArgs e)
        {
            GetNivdalData.GetNivdalData GND = new GetNivdalData.GetNivdalData();
            GND.ExecNivdalSQL("Title", "Text", "Language", "Nivdal_AddQnATip", NewTipTitle.Text.Trim(), NewTipTextBox.Text.Trim(), NewTipsLanguage.SelectedValue);
            NewTipTitle.Text = "";
            NewTipTextBox.Text = "";
            TipsListView.DataBind();
        }


    }
}